package com.huawei.appgallery.forum.user.usercenter.fragment;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.base.https.jgw.JGWTabDetailResponse;
import com.huawei.appgallery.forum.base.https.jgw.JGWTabInfo;
import com.huawei.appgallery.forum.user.api.IUserFollow;
import com.huawei.appgallery.forum.user.api.IUserHomePageProtocol;
import com.huawei.appgallery.forum.user.usercenter.activity.UserHomePageActivity;
import com.huawei.appgallery.forum.user.usercenter.bean.ForumUserHeadCardBean;
import com.huawei.appgallery.forum.user.usercenter.card.ForumUserHeadCard;
import com.huawei.appgallery.forum.user.usercenter.widget.NestScrollLayout;
import com.huawei.appgallery.forum.user.usercenter.widget.NestScrollLayout.d;
import com.huawei.appgallery.forum.user.usercenter.widget.UserHomePageViewPager;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.hms.framework.network.restclient.hwhttp.route.IPRoute;
import com.huawei.secure.android.common.intent.SafeIntent;
import huawei.widget.HwSubTabWidget;
import huawei.widget.HwSubTabWidget.b;
import java.util.List;
import o.bqx;
import o.brd;
import o.cbb;
import o.cbu;
import o.cbv;
import o.cbw;
import o.cbx;
import o.ccb;
import o.ciy;
import o.ciz;
import o.ContentManager;
import o.CollectCheck;
import o.MinimumFactory;
import o.fho;
import o.fjm;
import o.FragmentManager;
import o.FragmentTransaction;
import o.ll;

@FragmentDefine(alias = "UserHomePageFragment", protocol = IUserHomePageProtocol.class)
public class UserHomePageFragment extends Fragment implements b, d, cbx {
    private String ʹ;
    private int ʻˊ = -1;
    private c ʻˋ;
    private IUserFollow ʻᐝ;
    private fjm ʼ = fjm.ॱ(this);
    private int ʼˊ = -1;
    private String ʼˋ;
    private CardBean ʽ;
    private a ʽˋ;
    private HwSubTabWidget ˊ;
    private List<JGWTabInfo> ˋ;
    private LinearLayout ˎ;
    private UserHomePageViewPager ˏ;
    private NestScrollLayout ॱ;
    private ForumUserHeadCard ॱॱ;
    private cbw ᐝ;
    private JGWTabDetailResponse ﹳ;
    private String ﾞ;
    private cbv ﾟ;

    public interface a {
        void ˏ(int i);
    }

    final class c extends BroadcastReceiver {
        final /* synthetic */ UserHomePageFragment ˋ;

        private c(UserHomePageFragment userHomePageFragment) {
            this.ˋ = userHomePageFragment;
        }

        public void onReceive(Context context, Intent intent) {
            Intent safeIntent = new SafeIntent(intent);
            String ˎ = this.ˋ.ʻᐝ.ˎ(safeIntent);
            int ॱ = this.ˋ.ʻᐝ.ॱ(safeIntent);
            if (!TextUtils.isEmpty(ˎ)) {
                this.ˋ.ॱ(ˎ, ॱ);
            }
        }
    }

    public void ˏ(Bundle bundle) {
        IUserHomePageProtocol iUserHomePageProtocol = (IUserHomePageProtocol) this.ʼ.ॱ();
        this.ﾞ = iUserHomePageProtocol.getUri();
        this.ʹ = iUserHomePageProtocol.getUserId();
        this.ﹳ = iUserHomePageProtocol.getResponseBean();
        this.ʼˋ = iUserHomePageProtocol.getDomainId();
        this.ʻˊ = iUserHomePageProtocol.getLastScroll();
        this.ʼˊ = iUserHomePageProtocol.getLastSelectTab();
        this.ʻᐝ = (IUserFollow) fho.ˏ().ˋ("User").ॱ(IUserFollow.class);
        this.ʻˋ = new c();
        c_(true);
        super.ˏ(bundle);
    }

    public View ˋ(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        ViewGroup viewGroup2 = (ViewGroup) layoutInflater.inflate(cbb.d.ॱˊ, viewGroup, false);
        ˊ(viewGroup2, layoutInflater);
        ʽᐝ();
        return viewGroup2;
    }

    private void ˊ(ViewGroup viewGroup, LayoutInflater layoutInflater) {
        this.ॱ = (NestScrollLayout) viewGroup.findViewById(cbb.b.ˌॱ);
        this.ˊ = (HwSubTabWidget) viewGroup.findViewById(cbb.b.ͺˎ);
        this.ˏ = (UserHomePageViewPager) viewGroup.findViewById(cbb.b.ˏͺ);
        this.ˎ = (LinearLayout) viewGroup.findViewById(cbb.b.ˑॱ);
        this.ॱ.setOnScrollListener(this);
        ॱ(layoutInflater);
        int i = this.ʼˊ;
        ˋ(i);
        ॱॱ(i);
        this.ॱ.ˋ = this.ˎ;
        this.ॱ.ॱ = this.ˊ;
        this.ॱ.ˏ = this.ˏ;
        this.ॱ.setImmerse(true);
        if (this.ʻˊ > 0) {
            this.ॱ.ॱ(this.ʻˊ, IPRoute.INTERVAL);
        }
    }

    public void ॱ(Activity activity) {
        super.ॱ(activity);
        if (activity instanceof cbv) {
            this.ﾟ = (cbv) activity;
        }
        if (activity instanceof a) {
            this.ʽˋ = (a) activity;
        }
        if (ॱˋ() != null) {
            ((UserHomePageActivity) ॱˋ()).ॱ((cbx) this);
        } else {
            bqx.ॱ("UserHomePageFragment", "getActivity == null");
        }
    }

    private void ॱ(LayoutInflater layoutInflater) {
        this.ॱॱ = new ForumUserHeadCard(ॱˊ());
        View ˋ = this.ॱॱ.ˋ(layoutInflater);
        ˊ(this.ﹳ);
        this.ˎ.addView(ˋ);
        this.ॱ.setImmerseView(ˋ);
    }

    private void ˋ(int i) {
        if (this.ˋ != null && this.ˋ.size() > 0) {
            int size = this.ˋ.size();
            int i2 = 0;
            while (i2 < size) {
                CharSequence ᐝ = ((JGWTabInfo) this.ˋ.get(i2)).ᐝ();
                HwSubTabWidget hwSubTabWidget = this.ˊ;
                hwSubTabWidget.getClass();
                huawei.widget.HwSubTabWidget.a aVar = new huawei.widget.HwSubTabWidget.a(hwSubTabWidget, ᐝ, this);
                aVar.ˎ(i2);
                boolean z = (i < 0 || i >= size) ? i2 == 0 : i == i2;
                this.ˊ.ॱ(aVar, z);
                i2++;
            }
        }
    }

    private void ॱॱ(int i) {
        FragmentManager ˏॱ = ॱˋ().ˏॱ();
        if (VERSION.SDK_INT > 23) {
            ˏॱ = ʽॱ();
        }
        this.ᐝ = new cbw(ˏॱ, ॱˋ());
        this.ᐝ.ॱ(this.ˋ);
        this.ᐝ.ˏ(this.ʹ);
        this.ᐝ.ॱ(this.ʼˋ);
        this.ˏ.setAdapter(this.ᐝ);
        this.ˏ.addOnPageChangeListener(new ccb(this.ˊ));
        this.ˏ.setOffscreenPageLimit(1);
        if (i < 0 || i >= this.ˋ.size()) {
            this.ˏ.setCurrentItem(cbu.ˊ(this.ﾞ, this.ˋ));
        } else {
            this.ˏ.setCurrentItem(i);
        }
    }

    private void ˊ(JGWTabDetailResponse jGWTabDetailResponse) {
        this.ˋ = jGWTabDetailResponse.ˎ();
        List<LayoutData> ᐝॱ = jGWTabDetailResponse.ᐝॱ();
        if (ᐝॱ == null || ᐝॱ.size() <= 0) {
            bqx.ˋ("UserHomePageFragment", "layoutDataList is empty");
            return;
        }
        for (LayoutData layoutData : ᐝॱ) {
            if (layoutData.ˋ() != null && layoutData.ˋ().size() > 0) {
                this.ʽ = (CardBean) layoutData.ˋ().get(0);
                if (this.ʽ instanceof ForumUserHeadCardBean) {
                    CardBean cardBean = (ForumUserHeadCardBean) this.ʽ;
                    cardBean.ˍ(this.ﾞ);
                    this.ॱॱ.ˋ(cardBean);
                    return;
                }
                return;
            }
        }
    }

    private void ॱ(String str, int i) {
        bqx.ˊ("UserHomePageFragment", "refreshFollowStatus: " + i + "uid is null?" + TextUtils.isEmpty(str));
        if (this.ʽ instanceof ForumUserHeadCardBean) {
            User ˊ = ((ForumUserHeadCardBean) this.ʽ).ˊ();
            if (ˊ == null) {
                bqx.ॱ("UserHomePageFragment", "refreshFollowStatus failed: the user is null or has deleted");
                return;
            }
            if (ˊ.ʼ()) {
                if (str.equals(ˊ.ॱˋ())) {
                    ˏ(ˊ, i);
                } else {
                    ˋ(ˊ, i);
                }
            } else if (i != ˊ.ʻॱ() && str.equals(ˊ.ॱˋ())) {
                ˏ(ˊ, i);
                ˊ.ˎ(i);
            } else {
                return;
            }
            this.ॱॱ.ॱ(this.ʽ);
        }
    }

    public void ˋ(User user, int i) {
        if (i == 0) {
            user.ʼ(user.ˏॱ() - 1);
        } else {
            user.ʼ(user.ˏॱ() + 1);
        }
    }

    public void ˏ(User user, int i) {
        if (i == 0) {
            user.ᐝ(user.ˊॱ() - 1);
        } else {
            user.ᐝ(user.ˊॱ() + 1);
        }
    }

    protected void ॱ() {
        if (ॱˊ() != null) {
            ll.ˏ(ॱˊ()).ˋ(this.ʻˋ);
        }
    }

    protected void ʽᐝ() {
        IntentFilter ˎ = this.ʻᐝ.ˎ();
        if (ॱˊ() != null) {
            ll.ˏ(ॱˊ()).ˏ(this.ʻˋ, ˎ);
        }
    }

    public void ˊ(huawei.widget.HwSubTabWidget.a aVar, FragmentTransaction kaVar) {
        if (this.ᐝ != null) {
            Fragment ॱ = this.ᐝ.ॱ();
            if (ॱ instanceof ciy) {
                ((ciy) ॱ).ʾॱ();
            }
        }
    }

    public void ˎ(huawei.widget.HwSubTabWidget.a aVar, FragmentTransaction kaVar) {
        if (this.ˊ != null) {
            int ˊ = this.ˊ.ˊ();
            if (this.ˏ != null) {
                this.ˏ.setCurrentItem(ˊ);
            }
            if (this.ʽˋ != null) {
                this.ʽˋ.ˏ(ˊ);
            }
            if (ᐝ(ˊ)) {
                brd.ॱ.ॱ();
            }
            this.ʼˊ = ˊ;
        }
    }

    public void ॱ(huawei.widget.HwSubTabWidget.a aVar, FragmentTransaction kaVar) {
    }

    public void ˏ(int i, int i2) {
        this.ʻˊ = i;
        if (this.ﾟ != null) {
            this.ﾟ.ˊ(i, i2);
        }
    }

    public boolean ʾॱ() {
        if (!(this.ᐝ == null || this.ˏ == null)) {
            int ˋ = this.ˏ.getCurrentItem();
            if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                ˋ = (this.ᐝ.getCount() - 1) - ˋ;
            }
            Object ॱ = this.ᐝ.instantiateItem(this.ˏ, ˋ);
            if (ॱ instanceof ciz) {
                return ((ciz) ॱ).ad_();
            }
            bqx.ॱ("UserHomePageFragment", "unknown type, fragment:" + ॱ + ", uri:");
        }
        return false;
    }

    public void ˊ(String str, String str2) {
        this.ॱॱ.ˎ(str, str2);
    }

    public void ᐝ() {
        ॱ();
        super.ᐝ();
    }

    public void ˎˎ() {
        super.ˎˎ();
        if (this.ॱॱ != null) {
            this.ॱॱ.ˎ();
        }
    }

    private boolean ᐝ(int i) {
        if (CollectCheck.isEmpty(this.ˋ)) {
            return false;
        }
        if (this.ʼˊ == -1 && "forum|user_detail_review".equals(this.ﾞ)) {
            return true;
        }
        if (i >= 0 && i < this.ˋ.size()) {
            JGWTabInfo jGWTabInfo = (JGWTabInfo) this.ˋ.get(i);
            if (jGWTabInfo != null && "forum|user_detail_review".equals(jGWTabInfo.ʼ())) {
                return true;
            }
        }
        return false;
    }
}
